package com.yunchao.maintenance.data.datasource

import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import com.yunchao.maintenance.data.datasource.model.MaintenanceInfoEntityModel
import java.time.LocalDate

@Database(entities = [MaintenanceInfoEntityModel::class], version = 1, exportSchema = false)
@TypeConverters(LocalDateConverter::class)
internal abstract class MaintenanceDatabase : RoomDatabase() {

    abstract fun maintenanceInfoDao(): MaintenanceInfoDao
}



class LocalDateConverter {
    @TypeConverter
    fun fromLocalDate(date: LocalDate?): Long? {
        return date?.toEpochDay()
    }

    @TypeConverter
    fun toLocalDate(epochDay: Long?): LocalDate? {
        return epochDay?.let { LocalDate.ofEpochDay(it) }
    }
}